package com.kuang.exam.modules.user.lesson.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.kuang.exam.core.api.ApiRest;
import com.kuang.exam.core.api.controller.BaseController;
import com.kuang.exam.core.api.dto.PagingReqDTO;
import com.kuang.exam.modules.sys.depart.dto.SysDepartDTO;
import com.kuang.exam.modules.sys.depart.dto.UserDepartDTO;
import com.kuang.exam.modules.sys.depart.service.SysDepartService;
import com.kuang.exam.modules.sys.lesson.dto.SysLessonDTO;
import com.kuang.exam.modules.sys.lesson.dto.UserLessonDTO;
import com.kuang.exam.modules.sys.lesson.service.SysUserLessonService;
import com.kuang.exam.modules.sys.user.entity.SysUser;
import com.kuang.exam.modules.sys.user.service.SysUserService;
import com.kuang.exam.modules.user.UserUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 用户课程控制器
 * </p>
 */
@Api(tags = {"用户课程"})
@RestController
@RequestMapping("/exam/api/user/lesson")
public class UserLessonController extends BaseController {

    @Autowired
    private SysUserLessonService baseService;

    @Autowired
    private SysDepartService departService;

    @Autowired
    private SysUserService userService;

    /**
     * 当前用户角色
     *
     * @return
     */
    @ApiOperation(value = "当前用户角色")
    @RequestMapping(value = "/getRole", method = {RequestMethod.POST})
    public ApiRest<String> getRole() {
        SysUser user = userService.getById(UserUtils.getUserId());
        return super.success(user.getRoleIds());
    }

    /**
     * 分页查找
     *
     * @param reqDTO
     * @return
     */
    @ApiOperation(value = "分页查找")
    @RequestMapping(value = "/paging", method = {RequestMethod.POST})
    public ApiRest<IPage<UserLessonDTO>> paging(@RequestBody PagingReqDTO<UserLessonDTO> reqDTO) {

        //分页查询并转换
        IPage<UserLessonDTO> page = baseService.paging(reqDTO);
        return super.success(page);
    }

    /**
     * 当前用户的所有课程列表
     *
     * @return
     */
    @ApiOperation(value = "列表查找")
    @RequestMapping(value = "/list", method = {RequestMethod.POST})
    public ApiRest<List<UserLessonDTO>> list() {

        //分页查询并转换
        List<UserLessonDTO> list = baseService.listByUserId();
        return super.success(list);
    }


    /**
     * 查找用户班级
     *
     * @return
     */
    @ApiOperation(value = "查找用户班级")
    @RequestMapping(value = "/getDept", method = {RequestMethod.POST})
    public ApiRest<IPage<UserDepartDTO>> getDept(@RequestBody PagingReqDTO<SysDepartDTO> reqDTO) {
        IPage<UserDepartDTO> page = departService.getByUserId(reqDTO);
        return super.success(page);
    }

}
